import java.io.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;

import com.hp.hpl.jena.ontology.OntModel;

import ru.ksu.ktk.diploma.sdi.dao.ResourcesDao;
import ru.ksu.ktk.diploma.sdi.schema.SchemaGenerator;

@ContextConfiguration(locations = {"classpath:META-INF/spring/mapping-beans.xml", "classpath:test-dao-beans.xml",
    "classpath:test-properties-beans.xml", "classpath:META-INF/spring/analyzer-beans.xml"})
public class SchemaGeneratorTestCase extends AbstractTestNGSpringContextTests {
    @Autowired
    ResourcesDao resourcesDao;
    @Autowired
    SchemaGenerator schemaGenerator;

    @Test
    public void testGenerateSchema() throws IOException {
        String uri = "xmldb:exist://localhost:8080/exist/xmlrpc/db/mom/data/emku/sources/material-and-technique.xml";
        String contentSource = resourcesDao.loadContent(uri);

        InputStream stream = new ByteArrayInputStream(contentSource.getBytes("UTF-8"));
        OntModel sourceOntModel = schemaGenerator.generateSchema(stream);

        StringWriter writer = new StringWriter();
        sourceOntModel.write(writer, "RDF/XML-ABBREV");
        String content = writer.toString();
        String saveUri = "xmldb:exist://localhost:8080/exist/xmlrpc/db/mom/data/emku/sources";
        resourcesDao.save(saveUri, "material-and-technique.owl", content);
    }
}
